<?php
namespace app\admin\controller;
use think\Db;
use think\Request;
use think\Controller;
use app\admin\model\Orders;
use app\admin\model\Users;
class Order extends Common{
    public function _initialize()
    {
        parent::_initialize();
        $this->Order = new Orders;

    }
    	
   	public function index($page=null,$key=null){

   		if($this->request->isPost()){
            $page = (int)$page > 0 ? $page : 1;
            $map=[];
            if(!empty($key)){
                 $map['sn'] = ['like',"%".$key."%"];
            }
            if(!Users::isAdmin($this->User_id)){
	   			$map['user_id'] = $this->User_id;
	   		}
            $lists = $this->Order
                ->field("*,type as typelabel")
                ->order('id desc')
                ->where($map)
                ->paginate(array('list_rows'=>$this->pageSize,'page'=>$page))
                ->toArray();
            return $result = ['code'=>0,'msg'=>lang('No Data...'),'data'=>$lists['data'],'count'=>$lists['total'],'rel'=>1];
        }
    	return $this->fetch();
   	}
   	/*审计功能*/
   	public function detail($item_id=null){
       //Orders::add(154,$this->User_id,3);
   		$order = $this->Order->field("*,type as typelabel")->where(['id'=>$item_id])->find();
   		if(empty($order)){
   			$this->error(lang('Data does not exist'));
   		}
   		 $order['value'] = unserialize($order['value']);
   		//echo "<pre>";
   		//print_r($order['value']);exit;
   		$this->assign('order',$order);
   		return $this->fetch();
   	}
}